Skip to content

Conversation

@jnsdls
Copy link
Member

@jnsdls jnsdls commented Jan 31, 2025


PR-Codex overview

This PR refactors the login handling code in tw-login.js, improving the structure and logic for managing user authentication and session storage. It consolidates variable definitions and streamlines the login flow.

Detailed summary

  • Replaced destructured targetId, clientId, and baseUrl with a single globalSetup object.
  • Consolidated code handling user address and session key storage based on URL parameters.
  • Removed unused makeRequest function.
  • Simplified the onLogin function by using globalSetup variables.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@vercel
Copy link

vercel bot commented Jan 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
login ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 0:58am
4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Skipped (Inspect) Jan 31, 2025 0:58am
thirdweb_playground ⬜️ Skipped (Inspect) Jan 31, 2025 0:58am
thirdweb-www ⬜️ Skipped (Inspect) Jan 31, 2025 0:58am
wallet-ui ⬜️ Skipped (Inspect) Jan 31, 2025 0:58am

@vercel vercel bot temporarily deployed to Preview – docs-v2 January 31, 2025 00:55 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui January 31, 2025 00:55 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground January 31, 2025 00:55 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www January 31, 2025 00:55 Inactive
@changeset-bot
Copy link

changeset-bot bot commented Jan 31, 2025

⚠️ No Changeset found

Latest commit: 64336ae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member Author

jnsdls commented Jan 31, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jnsdls jnsdls marked this pull request as ready for review January 31, 2025 00:56
@jnsdls jnsdls requested review from a team as code owners January 31, 2025 00:56
@jnsdls jnsdls force-pushed the add_thirdweb_login_client_script branch from 64d3ed0 to 64336ae Compare January 31, 2025 00:56
@vercel vercel bot temporarily deployed to Preview – docs-v2 January 31, 2025 00:56 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground January 31, 2025 00:56 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui January 31, 2025 00:56 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb-www January 31, 2025 00:56 Inactive
@jnsdls jnsdls merged commit 60c5c26 into main Jan 31, 2025
26 of 29 checks passed
@jnsdls jnsdls deleted the add_thirdweb_login_client_script branch January 31, 2025 00:57
@@ -0,0 +1 @@
(()=>{const e=(()=> {const e=document.currentScript;if(!e)throw new Error("Could not find script element");const o=new URL(e.src).origin,t=e.dataset.clientId;if(!t)throw new Error("Missing client-id");return{clientId:t,baseUrl:o}})(),o="tw.login:userAddress",t="tw.login:sessionKeyAddress",n="tw.login:code";function r(){const o=window.crypto.getRandomValues(new Uint8Array(4)).join("");localStorage.setItem(n,o);const t=new URL(e.baseUrl);t.searchParams.set("code",o),t.searchParams.set("clientId",e.clientId),t.searchParams.set("redirect",window.location.href),window.location.href=t.href}!(()=> {const e=funci(f(=> !e.hash)return null;try{return functiont( o=> =e.startsWith("#")?e.slice(1):e,t=atob(o),n=JSON.parse(t);if("userAddress"in n&&"sessionKeyAddress"in n&&"code"in n)return n;return null}(e.hash))}catch{return null}}(new) URL(window.location));e&&e.code===localStorage.getItem(n)&&(window.location.hash="",localStorage.setItem(n,e.code),localStorage.setItem(o,e.userAddress),localStorage.setItem(t,e.sessionKeyAddress));const s=localStorage.getItem(o),i=localStorage.getItem(t);s&&i?(console.log("handleIsLoggedIn"),window.thirdweb={isLoggedIn:!0,getAddress:()=>localStorage.getItem(o),logout:()=>{window.localStorage.removeItem(o),window.localStorage.removeItem(t),window.location.reload()}}):window.thirdweb={login:r,isLoggedIn:!1}})()})(); No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The minified JavaScript contains syntax errors in the parseURLHash function implementation. Specifically, funci(f(=> and functiont( o=> are malformed arrow function expressions that will cause runtime errors. Please regenerate the minified file from the source code using a proper JavaScript minification tool to ensure the output is syntactically valid.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@codecov
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.87%. Comparing base (dc74c3b) to head (64336ae).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6125   +/-   ##
=======================================
  Coverage   56.87%   56.87%           
=======================================
  Files        1153     1153           
  Lines       63896    63896           
  Branches     5180     5180           
=======================================
  Hits        36344    36344           
  Misses      26825    26825           
  Partials      727      727           
Flag Coverage Δ *Carryforward flag
legacy_packages 65.68% <ø> (ø) Carriedforward from dc74c3b
packages 55.07% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

@github-actions
Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 46.6 KB (0%) 933 ms (0%) 658 ms (+29.6% 🔺) 1.6 s
thirdweb (cjs) 122.39 KB (0%) 2.5 s (0%) 984 ms (-5.91% 🔽) 3.5 s
thirdweb (minimal + tree-shaking) 5.58 KB (0%) 112 ms (0%) 134 ms (+132.87% 🔺) 246 ms
thirdweb/chains (tree-shaking) 506 B (0%) 10 ms (0%) 50 ms (+18.62% 🔺) 60 ms
thirdweb/react (minimal + tree-shaking) 19.28 KB (0%) 386 ms (0%) 181 ms (+84.43% 🔺) 567 ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants